package lc.activiti.contract.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lc.activiti.common.HttpRequestStatus;
import lc.activiti.common.LCExceptionUtils;
import lc.activiti.common.Result;
import lc.activiti.contract.service.IContractApprovalService;
import lc.activiti.contract.service.IContractAuditService;
import lc.activiti.model.SubApprovalModel;
import lombok.extern.slf4j.Slf4j;

/**
 * 审批服务
 */
@Slf4j
@RestController
@RequestMapping("/contractApprovalService")
public class ContractApprovalController {
	@Autowired
	private IContractApprovalService contractApprovalService;
	@Autowired
	private IContractAuditService contractAuditService;
	
	@PostMapping("/submitApproval")
	public Result<Object> submitApproval(@RequestBody SubApprovalModel subModel){
		Result<Object> result=new Result<>();
		try {
			contractApprovalService.submitApproval(subModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("submitApproval",e);
			return result;
		}
	}
	@PostMapping("/approvalSuccess")
	public Result<Object> approvalContract(@RequestBody SubApprovalModel subModel){
 		Result<Object> result=new Result<>();
		try {
			contractApprovalService.approvalSuccess(subModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("approvalSuccess",e);
			return result;
		}
	} 
	@PostMapping("/rejectApproval")
	public Result<Object> rejectAppContract(@RequestBody SubApprovalModel subModel){
		Result<Object> result=new Result<>();
		try {
			contractApprovalService.rejectApproval(subModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("rejectApproval",e);
			return result;
		}
	} 
	@PostMapping("/auditSuccess")
	public Result<Object> auditContract(@RequestBody SubApprovalModel subModel){
		Result<Object> result=new Result<>();
		try {
			contractAuditService.auditSuccess(subModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("auditSuccess",e);
			return result;
		}
	} 
	@PostMapping("/auditReject")
	public Result<Object> auditReject(@RequestBody SubApprovalModel subModel){
		Result<Object> result=new Result<>();
		try {
			contractAuditService.auditReject(subModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			e.printStackTrace();
			log.error("auditReject",e);
			return result;
		}
	} 
}
